<?php
namespace app\api\controller;

use app\model\ArtExhibition as A;

class ArtExhibition extends ApiBase
{

    //list 
    public function list()
    {
        $where = [];
        $where[] = ["status","=",1];
        $list = (new A())->where($where)->order('sort','desc')->paginate(input('limit/d'));
        $list = $list->toArray();
        $data = [];
        foreach ($list['data'] as  &$v) {
            $data[] = [
                'id' => $v['id'],
                'title' => $v['title'],
                'desc' => $v['desc'],
                'img' => $v['img'],
            ];
        }
        $res = [
            'data' => $data,
            'total' => $list['total'],
            'page' => $list['current_page'],
        ];
        return $this->returnApi($res,code: 0);
    }

        //detail 详情
        public function detail()
        {
            $id = input('id',0);
            if (empty($id)) {
                return $this->returnApi([],1,'id不能为空');
            }
            $detail = (new A())->where("id","=", $id)->find();
            if (empty($detail)) {
                return $this->returnApi([],1,"活动不存在");
            }
            $detail['img'] = $detail['img'];
            $detail['content'] =  $detail['content'];
            return $this->returnApi($detail,0,'成功');
        }
}